package vcp.gui.forms;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JTextField;

import vcp.common.IView;
import vcp.gui.components.VCPPanel;
import vcp.gui.forms.validators.DateValidator;
import vcp.gui.forms.validators.EmailValidator;
import vcp.gui.forms.validators.NameValidator;
import vcp.gui.forms.validators.NumericValidator;
import vcp.gui.forms.validators.Time24HoursValidator;

import java.sql.Date;

import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JRadioButton;
import javax.swing.JButton;










import java.awt.Color;
import java.awt.GridLayout;
import java.sql.Timestamp;




import java.util.Observable;
import java.util.Observer;

import com.toedter.calendar.JDateChooser;

public class OrderTemporaryForm extends VCPPanel implements Observer,IView {
	private JTextField textCID;
	private JLabel lblNewOrderError;

 
    private int OrderType;
	
	/* validators */
	private boolean isValidForm=false;
	private JTextField carNo_field;
	private JTextField hTimeLeave_field;
	private JTextField email_field;
	private JLabel lblLeaveDate;
	JDateChooser dateChooser;
	JDateChooser dateChooser2;
	private JLabel dotLabel2;
	private JTextField mTimeLeave_field;
	private JTextField hTimeStart_field;
	private JTextField mTimeStart_field;
	private JLabel lblLotNum;
	private JTextField lotNumField;
	JButton btnSend;

	public OrderTemporaryForm() {
		setBackground(Color.WHITE);
		  buildForm();
		 
		  
	}
	
	private void buildForm(){

		textCID = new JTextField();
		textCID.setColumns(10);

		JLabel lblCID = new JLabel("Customer ID");

		btnSend = new JButton("create");
		
		btnSend.setActionCommand("btnSend");

		lblNewOrderError = new JLabel("");
		lblNewOrderError.setForeground(Color.RED);
		
		carNo_field = new JTextField();
		carNo_field.setColumns(10);
		
		hTimeLeave_field = new JTextField();
		hTimeLeave_field.setColumns(10);
		
		email_field = new JTextField();
		email_field.setColumns(10);
		
		JLabel lblCarNumber = new JLabel("Car Number");
		
		JLabel lblLeaveTime = new JLabel("Leave Time");
		
		JLabel lblEmail = new JLabel("E-Mail");
		
		lblLeaveDate = new JLabel("Leave Date");
		
		dateChooser = new JDateChooser();
		
		dotLabel2 = new JLabel(":");
		
		mTimeLeave_field = new JTextField();
		mTimeLeave_field.setColumns(10);
		
		dateChooser2 = new JDateChooser();
		
		JLabel lblStartDate = new JLabel("Start Date");
		
		JLabel lblStartTime = new JLabel("Start Time");
		
		hTimeStart_field = new JTextField();
		hTimeStart_field.setColumns(10);
		
		JLabel dotLabel1 = new JLabel(":");
		
		mTimeStart_field = new JTextField();
		mTimeStart_field.setColumns(10);
		
		lblLotNum = new JLabel("Lot Number");
		
		lotNumField = new JTextField();
		lotNumField.setColumns(10);
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
							.addGroup(groupLayout.createSequentialGroup()
								.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
									.addComponent(lblNewOrderError)
									.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
										.addGroup(groupLayout.createSequentialGroup()
											.addComponent(lblCID)
											.addGap(41)
											.addComponent(textCID, GroupLayout.PREFERRED_SIZE, 285, GroupLayout.PREFERRED_SIZE))
										.addGroup(groupLayout.createSequentialGroup()
											.addComponent(lblLeaveDate, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
											.addGap(18)
											.addComponent(dateChooser, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
										.addComponent(carNo_field, GroupLayout.PREFERRED_SIZE, 285, GroupLayout.PREFERRED_SIZE)
										.addGroup(groupLayout.createSequentialGroup()
											.addComponent(lblStartTime, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(hTimeStart_field, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(dotLabel1, GroupLayout.PREFERRED_SIZE, 4, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(mTimeStart_field, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
											.addComponent(lblStartDate, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
											.addGap(18)
											.addComponent(dateChooser2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
										.addComponent(lotNumField, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)))
								.addContainerGap(39, Short.MAX_VALUE))
							.addGroup(groupLayout.createSequentialGroup()
								.addComponent(lblLeaveTime, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(hTimeLeave_field, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(dotLabel2)
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(mTimeLeave_field, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
								.addContainerGap(285, Short.MAX_VALUE))
							.addGroup(groupLayout.createSequentialGroup()
								.addComponent(lblCarNumber, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
								.addContainerGap(365, Short.MAX_VALUE))
							.addGroup(groupLayout.createSequentialGroup()
								.addComponent(lblEmail, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(email_field, GroupLayout.PREFERRED_SIZE, 208, GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(lblLotNum, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
								.addGap(66)))
						.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
							.addComponent(btnSend)
							.addGap(182))))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblNewOrderError)
						.addGroup(groupLayout.createSequentialGroup()
							.addContainerGap()
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblCID)
								.addComponent(textCID, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblCarNumber)
						.addComponent(carNo_field, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(dateChooser2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addGap(14))
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblStartDate)
								.addComponent(lblStartTime)
								.addComponent(hTimeStart_field, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(dotLabel1)
								.addComponent(mTimeStart_field, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGap(18)))
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
							.addComponent(lblLeaveTime)
							.addComponent(hTimeLeave_field, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addComponent(dotLabel2)
							.addComponent(mTimeLeave_field, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addComponent(lblLeaveDate))
						.addComponent(dateChooser, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblEmail)
						.addComponent(email_field, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblLotNum)
						.addComponent(lotNumField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(btnSend)
					.addContainerGap(8, Short.MAX_VALUE))
		);
		setLayout(groupLayout);

	}

	@Override
	public void addController(Object obj) {
		btnSend.addActionListener((ActionListener)obj);
		btnSend.setActionCommand("orderTemporary");		
	}

	@Override
	public void update(Observable o, Object arg) {
		//if(arg.toString().equals("createTemporaryOrderOK"))
			   System.out.println(arg);	
	}

	public JTextField getTextCID() {
		return textCID;
	}

	public void setTextCID(JTextField textCID) {
		this.textCID = textCID;
	}

	public JLabel getLblNewOrderError() {
		return lblNewOrderError;
	}

	public void setLblNewOrderError(JLabel lblNewOrderError) {
		this.lblNewOrderError = lblNewOrderError;
	}

	public int getOrderType() {
		return OrderType;
	}

	public void setOrderType(int orderType) {
		OrderType = orderType;
	}

	public JTextField getCarNo_field() {
		return carNo_field;
	}

	public void setCarNo_field(JTextField carNo_field) {
		this.carNo_field = carNo_field;
	}

	public JTextField gethTimeLeave_field() {
		return hTimeLeave_field;
	}

	public void sethTimeLeave_field(JTextField hTimeLeave_field) {
		this.hTimeLeave_field = hTimeLeave_field;
	}

	public JTextField getEmail_field() {
		return email_field;
	}

	public void setEmail_field(JTextField email_field) {
		this.email_field = email_field;
	}

	public JLabel getLblLeaveDate() {
		return lblLeaveDate;
	}

	public void setLblLeaveDate(JLabel lblLeaveDate) {
		this.lblLeaveDate = lblLeaveDate;
	}

	public JDateChooser getDateChooser() {
		return dateChooser;
	}

	public void setDateChooser(JDateChooser dateChooser) {
		this.dateChooser = dateChooser;
	}

	public JDateChooser getDateChooser2() {
		return dateChooser2;
	}

	public void setDateChooser2(JDateChooser dateChooser2) {
		this.dateChooser2 = dateChooser2;
	}

	public JLabel getDotLabel2() {
		return dotLabel2;
	}

	public void setDotLabel2(JLabel dotLabel2) {
		this.dotLabel2 = dotLabel2;
	}

	public JTextField getmTimeLeave_field() {
		return mTimeLeave_field;
	}

	public void setmTimeLeave_field(JTextField mTimeLeave_field) {
		this.mTimeLeave_field = mTimeLeave_field;
	}

	public JTextField gethTimeStart_field() {
		return hTimeStart_field;
	}

	public void sethTimeStart_field(JTextField hTimeStart_field) {
		this.hTimeStart_field = hTimeStart_field;
	}

	public JTextField getmTimeStart_field() {
		return mTimeStart_field;
	}

	public void setmTimeStart_field(JTextField mTimeStart_field) {
		this.mTimeStart_field = mTimeStart_field;
	}

	public JLabel getLblLotNum() {
		return lblLotNum;
	}

	public void setLblLotNum(JLabel lblLotNum) {
		this.lblLotNum = lblLotNum;
	}

	public JTextField getLotNumField() {
		return lotNumField;
	}

	public void setLotNumField(JTextField lotNumField) {
		this.lotNumField = lotNumField;
	}

	public JButton getBtnSend() {
		return btnSend;
	}

	public void setBtnSend(JButton btnSend) {
		this.btnSend = btnSend;
	}


}
			
			
		